<?php

namespace App\Models;

/**
 * @mixin IdeHelperAgentConfig
 */
class AgentConfig extends BaseModel
{
    // 短信
    public const SMS_PROVIDER = 'sms_provider';
    public const ALI_ACCESS_KEY_ID = 'ali_access_key_id';
    public const ALI_ACCESS_KEY_SECRET = 'ali_access_key_secret';
    public const SMS_SIGN_NAME = 'sms_sign_name';
    public const VERIFY_CODE_TEMPLATE = 'verify_code_template';
    // 支付
    public const PAY_MERCHANT_NO = 'pay_merchant_no';
    public const PAY_SERVICE_FEE_RATE = 'pay_service_fee_rate';
    public const PAY_RESALE_SERVICE_FEE_RATE = 'pay_resale_service_fee_rate';
    public const PAY_RESALE_AGENT_FEE_RATE = 'pay_resale_agent_fee_rate';
    public const PAY_CHANNEL = 'pay_channel';
    public const ADAPAY_APP_ID = 'adapay_app_id';
    public const ADAPAY_DIVIDE_ID = 'adapay_divide_id';
    public const ADAPAY_API_KEY = 'adapay_api_key';
    public const ADAPAY_RSA_PUBLIC_KEY = 'adapay_rsa_public_key';
    public const ADAPAY_RSA_PRIVATE_KEY = 'adapay_rsa_private_key';
    public const SDPAY_MERCH_NO = 'sdpay_merch_no';
    public const SDPAY_RSA_PRIVATE_KEY = 'sdpay_rsa_private_key';

    // 寻程
    public const XUNCHENG_OCR_APPKEY = 'xuncheng_ocr_appkey';
    public const XUNCHENG_REALNAME_APPKEY = 'xuncheng_realname_appkey';
    public const XUNCHENG_SMS_APPKEY = 'xuncheng_sms_appkey';
    public const XUNCHENG_VERIFY_CODE_TEMPLATE = 'xuncheng_verify_code_template';
    // 登记
    public const REGISTRY_DEFAULT_PRICE = 'registry_default_price';
    public const REGISTRY_PRICE_PER_CATEGORY = 'registry_price_per_category';
    // 商品
    public const PRODUCT_PURCHASE_NOTICE = 'product_purchase_notice';
    public const PRODUCT_RESALE_MAX_PRICE = 'product_resale_max_price';
    public const PRODUCT_RESALE_NOTICE = 'product_resale_notice';
    public const PRODUCT_RESALE_CANCEL_LOCK_TIME = 'product_resale_cancel_lock_time';
    // 订单
    public const ORDER_LOCK_MINUTES = 'order_lock_minutes';
    public const ORDER_DAILY_CANCEL_LIMIT = 'order_daily_cancel_limit';
    public const RESALE_ORDER_DAILY_CANCEL_LIMIT = 'resale_order_daily_cancel_limit';
    //网站设置
    public const WEBSITE_NAME = 'website_name';
    public const WEBSITE_LOGO = 'website_logo';
    public const WEBSITE_ENABLE_RESALE = 'website_enable_resale';
    public const WEBSITE_ENABLE_EXCHANGE = 'website_enable_exchange';
    public const WEBSITE_ENABLE_CONVERT = 'website_enable_convert';
    public const WEBSITE_AGREEMENT = 'website_agreement';
    public const WEBSITE_PRIVACY = 'website_privacy';
    public const WEBSITE_ABOUTUS = 'website_aboutus';
    //交易所
    public const HEZHI_KEY = 'hezhi_key';
    public const HEZHI_URL = 'hezhi_url';
    public const DING_PUB_KEY = 'ding_pub_key';
    public const DING_PRIV_KEY = 'ding_priv_key';

    //钱包
    public const OPEN_WALLET_FEE = 'open_wallet_fee';

    //用户注册
    public const DAILY_REGISTER_LIMIT = 'daily_register_limit';
    public const CHANNEL_REGISTER_ONLY = 'channel_register_only';

    public static function listConfigsByAgentId($agentId)
    {
        return self::query()
            ->where('agent_id', $agentId)
            ->get()
            ->mapWithKeys(function (self $config) {
                return [$config->config_key => $config->config_value];
            });
    }

    public static function getConfig($agentId, $configKey, $default = null)
    {
        $config = self::query()
            ->where('agent_id', $agentId)
            ->where('config_key', $configKey)
            ->first();

        if ($config) {
            return $config->config_value;
        }

        return $default;
    }
}
